<script setup>
import { useRoute, useRouter } from "vue-router";
import { onMounted, reactive } from "vue";
import { getMingshi, getMingshiList } from "@/http/api";
const route = useRoute();
const router = useRouter();
const data = reactive({
  id: "",
  teacherGoods: {}, // 数据
  teacherList: [], // 列表
});
const { id } = route.query;
data.id = id;

// console.log(id);
onMounted(() => {
  getMings(); // 调用名师详情数据
  getList(); // 调用名师详情列表数据
});
// 名师详情数据
const getMings = async () => {
  const res = await getMingshi({ id: data.id });
  data.teacherGoods = res;
  //   console.log(res);
};
// 名师详列表数据
const getList = async () => {
  const res = await getMingshiList({ id: data.id });
  data.teacherList = res;
  //   console.log(res);
};
</script>
<template>
  <div class="mings">
    <header>
      <van-icon name="arrow-left" @click="$router.back()" />
      <h3>课程详情</h3>
      <p>全部老师</p>
    </header>
    <div class="box">
      <div class="box1">
        <img :src="data.teacherGoods.avatar" alt="" />
        <p>{{ data.teacherGoods.name }}</p>
      </div>
      <div class="box2">
        <p>{{ data.teacherGoods.teacher_info }}</p>
      </div>
    </div>
    <!-- 列表 -->
    <ul>
      <li
        v-for="(item, index) in data.teacherList"
        :key="item.id"
        @click="$router.push(`/goods/${item.id}`)"
      >
        <span class="sp">{{ item.course_classify_title }}</span>
        <p class="p1">{{ item.title }}</p>
        <div class="div1">
          <p
            v-for="(item1, index1) in item.teacher"
            :key="index1"
            class="teacher"
          >
            <img :src="item1.avatar" alt="" />
            <span>{{ item1.teacher_name }}</span>
          </p>
        </div>
        <div class="ren">
          <p>{{ item.sales_num }}人已报名</p>
          <p style="color: red">
            ￥{{ index == 0 ? "免费" : item.price / 100 + ".00" }}
          </p>
        </div>
      </li>
    </ul>
  </div>
</template>
<style lang="scss" scoped>
.mings {
  header {
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 40px;
    h3 {
      font-size: 42px;
    }
    p {
      font-size: 24px;
    }
  }
  .box {
    margin-top: -20px;
    .box1 {
      height: 450px;
      background: skyblue;
      text-align: center;
      overflow: hidden;
      padding-top: 40px;
      box-sizing: border-box;
      img {
        width: 120px;
        height: 120px;
        border-radius: 50%;
      }
      p {
        font-size: 36px;
        color: #fff;
        margin-top: 0;
      }
    }
    .box2 {
      width: 85%;
      margin: -100px auto 0 auto;
      padding: 20px 40px;
      background: #fff;
      //   margin-top: -100px;
      border-radius: 0.13333rem;
      p {
        font-size: 26px;
        line-height: 40px;
      }
    }
  }
  ul {
    padding: 0 20px;
    margin-top: 150px;
    margin-bottom: 100px;

    li {
      font-size: 32px;
      margin: 30px 0;
      background: #fff;
      border-radius: 20px;
      box-shadow: 0 0.04rem 0.09333rem 0 hsl(0deg 0% 81% / 35%);
      .sp {
        width: 120px;
        font-size: 25px;
        padding: 10px 10px;
        background: orangered;
        color: #fff;
      }
      .p1 {
        margin-left: 20px;
      }
      .div1 {
        display: flex;
        align-items: center;
        margin: 40px 40px;
        .teacher {
          margin: 20px 20px;
        }
        img {
          width: 50px;
          height: 50px;
          vertical-align: middle;
          border-radius: 50%;
        }
        span {
          margin-left: 10px;
          font-size: 20px;
        }
      }
      .ren {
        display: flex;
        justify-content: space-between;
        padding: 0 40px;
      }
    }
  }
}
</style>
